import sqlite3,os
import pymysql
import config.DBConfig as dbc

def connection_db():
    try:
        # 替换为你的 MySQL 服务器信息
        conn = pymysql.connect(
            host=dbc.HOSTNAME,
            user=dbc.USERNAME,
            password=dbc.PASSWORD,
            database=dbc.DATABASE,
            port=dbc.PORT,  # MySQL 默认端口
            # cursorclass=pymysql.cursors.DictCursor  # 可选：让 execute() 返回字典而不是元组，可能更方便
        )
        print("成功连接到 MySQL 数据库")
        return conn
    except pymysql.MySQLError as e:
        print(f"连接 MySQL 失败: {e}")
        return None




def create_table_user(sql):
    try:
        db = connection_db()
        db.execute(sql)
        db.commit()
        db.close()
    except BaseException as e:
        print("提示：", e)

def insert_table_user(sql):
    try:
        db = connection_db()
        db.execute(sql)
        db.commit()
        db.close()
    except BaseException as e:
        print("提示：", e)
